/**
 * JavaScript Cookie对象
 */
Cookies = function(){
	//写Cookie
	this.addCookie = function(_name,_value){
		var exp = new Date();
		exp.setTime(exp.getTime()+30*24*60*60*1000);
		document.cookie=_name+"="+unicode(_value)+";expires="+exp.toGMTString();
	}
	//得到Cookie
	this.getCookie = function(_name){
		var arrStr = document.cookie.split(";");
		var result = "";
		for(var i = 0;i<arrStr.length;i++){
			var temp = arrStr[i].split("=");
			var name = temp[0];
			var val = temp[1];
			if(name==_name){
				result = runicode(val);
				break;
			}
		}
		return result;
	}
	//删除指定名称的cookie
	this.delCookie = function(_name){
		var day = new Date();
		day.setTime(day.getTime()-10000);
		var cval = getCookie(_name);
		if(cval!=null){
      		document.cookie = _name+"="+cval+";expires="+day.toGMTString();
   		}
	}
	
	//字符串加密	
	function unicode(s){
		var len = s.length;
   		var rs = "";
	    for(var i = 0;i<len;i++){
	       var k = s.substring(i,i+1);
	       rs+=(i==0?"":"#")+s.charCodeAt(i);
	    }
   		return rs;
	}
	//字符串解密	
	function runicode(s){
		var k = s.split("#");
   		var rs = "";
	    for(var i = 0;i<k.length;i++){
	       rs+=String.fromCharCode(k[i]);
	    }
   		return rs;
	}
}